package cn.gson.crm.controller.student;

import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.ApplyDao;
import cn.gson.crm.model.dao.CustomerDao;
import cn.gson.crm.model.dao.OrderDao;
import cn.gson.crm.model.dao.RecordsDao;
import cn.gson.crm.model.entity.Apply;
import cn.gson.crm.model.entity.Employee;
import cn.gson.crm.vo.CustomerVo;
import cn.gson.crm.vo.OrderVo;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 签约，上传合同
 */
@WebServlet("/student/sign")
public class StudentSign extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private OrderDao orderDao = new OrderDao();
	private RecordsDao recordDao = new RecordsDao();
	
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String page  = request.getParameter("page");
		//String search = request.getParameter("search");
		//if (page == null || page.isEmpty()) {
		//	page = "1";
		//}
		//当前页数据
		//List<OrderVo> orderList = orderDao.getOrderAllList(12,Integer.parseInt((String)page),search);
		//总页数
		//int totalPage = orderDao.getTotalPage(12,search);

		//request.setAttribute("queryString", noPageQueryString(request));
		//request.setAttribute("orderList", orderList);
		//request.setAttribute("totalPage", totalPage);
		//request.setAttribute("page", page);
		//forward("student/stu_sign.jsp");
		
		Employee e = (Employee) request.getSession().getAttribute("emp");
		List<CustomerVo> custList = new CustomerDao().getAllCustomer(e.getEmpId(),12);
		request.getSession().setAttribute("custList", custList);
		request.getSession().setAttribute("listCust", custList.size());
		forward("student/stu_sign.jsp");
		return;
	}
	
	/**
	 * 
	 * @param request
	 * @return
	 */
	private String noPageQueryString(HttpServletRequest request) {
		Map<String, String[]> params = request.getParameterMap();

		String paramsStr = "";
		int i = 0;
		for (String key : params.keySet()) {
			if ("page".equals(key)) {
				continue;
			}
			String[] valus = params.get(key);
			String query = "";
			for (int j = 0; j < valus.length; j++) {
				query += key + "=" + valus[j];
				if (j < valus.length - 1) {
					query += "&";
				}
			}
			paramsStr += query;
			if (i < params.keySet().size() - 1) {
				paramsStr += "&";
			}
			i++;
		}
		return paramsStr.isEmpty() ? "" : "&" + paramsStr;
	}


}
